/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package mnstudent.presentationlayer;

import mnstudent.global.MyTableCellRender;
import mnstudent.global.DataTable;
import mnstudent.global.Standard;
import mnstudent.businessLayer.PositionBLL;
import mnstudent.businessLayer.RegulationBLL;
import mnstudent.businessLayer.StaffBLL;
import mnstudent.datatranferobject.PositionDTO;
import mnstudent.datatranferobject.StaffDTO;
import mnstudent.security.MD5;
import java.awt.Dimension;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.event.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;


public class frmStaff extends javax.swing.JPanel {

    private StaffBLL m_StaffBLL;
    private PositionBLL m_PositionBLL;
    private RegulationBLL m_RegulationBLL;
    
    private ArrayList<PositionDTO> listPositionObj;
    PositionDTO objAddNew;//doi tuong khoa khi chon se mo len Cua so them moi khoa
    private int currentRow = 0;
    //private boolean m_isSave = false;
    private DefaultTableModel m_Model;
    private final SimpleDateFormat formatDate= new SimpleDateFormat("dd/MM/yyyy");
    private int minAge, maxAge;

    /**
     * Creates new form frmFaculty
     */
    public frmStaff() {
        initComponents();
        initControls();
        prepare();
    }

    /**
     * Init Controls
     */
    private void initControls() {
       
        jxTxtStaffID.setEditable(false);//luon luon false
        jxtabDetails.setEditable(false);
        jxTxtUserName.setEditable(false);
        
        //neu chua them moi thi EditTable = false
        if (!this.jxtabDetails.m_isAdd && !this.jxtabDetails.m_isUpdate) {

            jxTxtNameOfStaff.setEditable(false);
            jxTxtPhone.setEditable(false);
            jxTxtAddress.setEditable(false);

            jxCbGender.setEnabled(false);
            jxCbPosition.setEnabled(false);
            jxDpBirthday.setEditable(false);
            
            jxBtnSave.setEnabled(false);
            jxBtnCancel.setEnabled(false);

            jxBtnAdd.setEnabled(true);
            jxBtnUpdate.setEnabled(true);
            jxBtnDelete.setEnabled(true);
        } else {

            jxTxtNameOfStaff.setEditable(true);
            jxTxtPhone.setEditable(true);
            jxTxtAddress.setEditable(true);

            jxCbGender.setEnabled(true);
            jxCbPosition.setEnabled(true);
            jxDpBirthday.setEditable(true);
            
            jxBtnSave.setEnabled(true);
            jxBtnCancel.setEnabled(true);

            jxBtnAdd.setEnabled(false);
            jxBtnUpdate.setEnabled(false);
            jxBtnDelete.setEnabled(false);
        }
    }

    /**
     * Phương thức set max lenght lon nhat cho cac textField
     */
    public void setMaxLenghtForTextField()
    {
        //TextField So dien thoai
        jxTxtPhone.addKeyListener(new KeyAdapter() {
                public void keyTyped(KeyEvent e) {
                    char vChar = e.getKeyChar();
                    int len = jxTxtPhone.getText().length();
                    if (!(Character.isDigit(vChar)
                            || (vChar == KeyEvent.VK_BACK_SPACE)
                            || (vChar == KeyEvent.VK_DELETE)
                            || (vChar == KeyEvent.VK_ENTER)
                            || (vChar == KeyEvent.VK_TAB))||(len > Standard.MAX_LEN_PHONE)) {
                            e.consume();
                    }
                }
        });
        //TextField Ho ten nhan vien
        jxTxtNameOfStaff.addKeyListener(new KeyAdapter() {
                public void keyTyped(KeyEvent e) {
                    int len = jxTxtNameOfStaff.getText().length();
                    if (len > Standard.MAX_LEN) {
                            e.consume();
                    }
                }
        });
        //TextField Dia chi nhan vien
        jxTxtAddress.addKeyListener(new KeyAdapter() {
                public void keyTyped(KeyEvent e) {
                    int len = jxTxtAddress.getText().length();
                    if (len > Standard.MAX_LEN) {
                            e.consume();
                    }
                }
        });
    }
    
    /**
     * Phương thức khởi tạo và chuẩn bị
     */   
    private void prepare(){
        //Set lai text cac button cua dialog
        UIManager.put("OptionPane.cancelButtonText", "Hủy");
        UIManager.put("OptionPane.noButtonText", "Không");
        UIManager.put("OptionPane.okButtonText", "Có");
        UIManager.put("OptionPane.yesButtonText", "Vâng");
        //
        this.m_StaffBLL = new StaffBLL();
        this.m_PositionBLL = new PositionBLL();
        m_RegulationBLL = new RegulationBLL();
        minAge = Integer.valueOf(m_RegulationBLL.getRegulationByLabelToObject("TuoiToiThieuNhanVien").getValue());
        maxAge = Integer.valueOf(m_RegulationBLL.getRegulationByLabelToObject("ToiToiDaNhanVien").getValue());
        //set max lenght lon nhat cho cac textField
        setMaxLenghtForTextField();
   
        bindingDataToComboBox();
        m_Model = (DefaultTableModel) jxtabDetails.getModel();
        
        DataTable.addRowForStaff(m_StaffBLL.getAllStaff(), m_PositionBLL.getAllIdAndNameOfPositionToArray(), m_Model);
        //get selected item
        jxtabDetails.setDefaultRenderer(Object.class, new MyTableCellRender());
        jxtabDetails.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent lse) {

                if (!(jxtabDetails.getSelectionModel().isSelectionEmpty())) {
                    //retrieving the selected row index
                    currentRow = jxtabDetails.getSelectedRow();
                    //if a single row is selected from the table, take each cell values into the controls
                    if (jxtabDetails.getRowSelectionAllowed() && jxtabDetails.getRowCount() > 0) {
                        if (jxtabDetails.m_isAdd || jxtabDetails.m_isUpdate) {
                            int rs = JOptionPane.showOptionDialog(null,
                                    "Vui lòng lưu thay đổi trước khi chuyển sang dòng khác!",
                                    "Cảnh báo",
                                    JOptionPane.YES_NO_OPTION,
                                    JOptionPane.QUESTION_MESSAGE,
                                    null,
                                    null,
                                    null);
                            if (rs == 0)//Yes
                            {
                                save();
                            } else {
                                cancelAction();
                            }
                        } else {
                            
                            bindingDataToControls();
                        }
                    }
                }
            }
        });
        //neu co dl thi do mac dinh row dau tien
        if (jxtabDetails.getRowCount() > 0) {
            jxtabDetails.setRequestFocusEnabled(true);
            jxtabDetails.requestFocus();
            jxtabDetails.changeSelection(jxtabDetails.getRowCount() - 1, jxtabDetails.getRowCount() - 1, false, false);
        }
    }

    /**
     * Phương thức gán giá trị cho các controls khi thay đổi dòng trên JTable
     */
    private void bindingDataToControls()
    {
        jxTxtStaffID.setText(jxtabDetails.getStringAt(jxtabDetails.getSelectedRow(), 0));
        jxTxtNameOfStaff.setText(jxtabDetails.getStringAt(jxtabDetails.getSelectedRow(), 1));
        jxTxtPhone.setText(jxtabDetails.getStringAt(jxtabDetails.getSelectedRow(), 4));
        jxTxtAddress.setText(jxtabDetails.getStringAt(jxtabDetails.getSelectedRow(), 5));

        if (!jxtabDetails.getValueAt(currentRow, 2).equals("")) {
            jxCbGender.setSelectedItem(jxtabDetails.getValueAt(currentRow, 2));
        }
        //ComboBox Chuc vu
        if (!jxtabDetails.getValueAt(currentRow, 6).equals("")) {
            PositionDTO objPosition = (PositionDTO) jxtabDetails.getValueAt(currentRow, 6);
            jxCbPosition.setSelectedItem(objPosition);
        }

        if(!jxtabDetails.getStringAt(jxtabDetails.getSelectedRow(), 3).equals(""))
        {
            try {
                jxDpBirthday.setDate(formatDate.parse(jxtabDetails.getStringAt(jxtabDetails.getSelectedRow(), 3)));
            } catch (ParseException ex) {
               ex.printStackTrace();
            }
        }
        jxTxtUserName.setText(jxtabDetails.getStringAt(jxtabDetails.getSelectedRow(), 7));
    }
    /**
     * Phương thức đổ dữ liệu vào các combobox
     */
    private void bindingDataToComboBox() {
        
        //ComboxBox Doi tuong
        listPositionObj = m_PositionBLL.getAllIdAndNameOfPositionToArray();
        objAddNew = new PositionDTO("CVThemMoi", "Thêm mới...");
        listPositionObj.add(objAddNew);
        DefaultComboBoxModel dfCbModel = new DefaultComboBoxModel(listPositionObj.toArray());
        jxCbPosition.setModel(dfCbModel);
        
        //ComboBox Gioi tinh
        String[] arrGender = {"Nam", "Nữ"};
        DefaultComboBoxModel dfCbModelGender = new DefaultComboBoxModel(arrGender);
        jxCbGender.setModel(dfCbModelGender);
    }
    /**
     * Phương thức khởi gán lại giá trị cho các controls
     */
    private void resetControls()
    {
        jxTxtStaffID.setText("NV0000***");
        jxTxtNameOfStaff.setText("");
        jxTxtNameOfStaff.requestFocus();
        jxTxtAddress.setText("");
        jxTxtPhone.setText("");
        jxTxtUserName.setText("");
        jxDpBirthday.setDate(null);

        jxCbGender.setSelectedItem(null);
        jxCbPosition.setSelectedItem(null);
        
    }
    
    /**
     * Refresh Data Table
     */
    private void refreshDataInJTable() {
        m_Model.fireTableDataChanged();
        m_Model.fireTableStructureChanged();
        m_Model.getDataVector().removeAllElements();
        DataTable.addRowForStaff(m_StaffBLL.getAllStaff(), m_PositionBLL.getAllIdAndNameOfPositionToArray(), m_Model);
        if (jxtabDetails.getRowCount() > 0) {
            jxtabDetails.setRequestFocusEnabled(true);
            jxtabDetails.requestFocus();
            jxtabDetails.changeSelection(jxtabDetails.getRowCount() - 1, jxtabDetails.getRowCount() - 1, false, false);
        }
    }

    /**
     * Phương thức xoa 1 nhân viên dc chon
     *
     * @param rowSelected
     * @return
     */
    private boolean isDelete(int rowSelected) {
        boolean m_isDelete = false;
        
        String id = this.jxtabDetails.getValueAt(rowSelected, 0).toString();
        String name = this.jxtabDetails.getValueAt(rowSelected, 1).toString();
        StaffDTO staffObj = new StaffDTO(id, name);
        if (m_StaffBLL.deleteStaffFromDatabase(staffObj)) {
            m_Model.removeRow(rowSelected);
            m_isDelete = true;
        }

        return m_isDelete;
    }

    /**
     * Phương thức xoa 1 luc nhieu nhân viên
     *
     * @return
     */
    private boolean isDeleteMoreStaff() {
        boolean m_isDelete = true;
        int[] arrRowSelected = this.jxtabDetails.getSelectedRows();
        for (int i = arrRowSelected.length - 1; i >= 0; i--) {
            if (!isDelete(arrRowSelected[i])) {
                JOptionPane.showMessageDialog(null,
                        "Xóa thất bại khoa: " + jxtabDetails.getValueAt(arrRowSelected[i], 1),
                        "Lỗi",
                        JOptionPane.YES_OPTION);
                m_isDelete = false;
            }
        }
        return m_isDelete;
    }

    /**
     * Phương thức thuc hien viec cap nhat va update
     */
    private void save() {
        if (this.jxtabDetails.m_isAdd) {
            saveToDatabase();
        } else if (this.jxtabDetails.m_isUpdate) {
           updateToDatabase();
        }
    }

    /**
     * Phương thức thuc hien insert Nhân viên xuong database
     *
     * @return
     */
    private void saveToDatabase() {
        
        if (checkData()) {

            String id = "NV0000***";//Ma nhan vien
            String name = Standard.standardNamePerson(this.jxTxtNameOfStaff.getText());//ten nhan vien
            String gender = this.jxCbGender.getSelectedItem().toString();//gioi tinh
            //Chuc vu
            PositionDTO objPosition = (PositionDTO) this.jxCbPosition.getSelectedItem();
            String idPosition= objPosition.getPositionID();//Ma chuc vu
            String phone = jxTxtPhone.getText().trim();
            String address = Standard.standardName(jxTxtAddress.getText().trim());
            java.sql.Date d = new java.sql.Date(jxDpBirthday.getDate().getYear(), 
                    jxDpBirthday.getDate().getMonth(),jxDpBirthday.getDate().getDate());//Ngay sinh
            String userName = jxTxtUserName.getText().trim();
            
            StaffDTO staffObj = new StaffDTO(id, name, gender, 
                    d, phone, address, idPosition, userName, MD5.Hash("123456"));
            if (m_StaffBLL.insertStaffToDatabase(staffObj)) {
               JOptionPane.showOptionDialog(null,
                        "Lưu xuống thành công!",
                        "Thông báo",
                        JOptionPane.YES_OPTION,
                        JOptionPane.QUESTION_MESSAGE,
                        null,
                        null,
                        null);
                //neu luu thanh cong
                this.jxtabDetails.m_isAdd = false;
                initControls();
                refreshDataInJTable();
            } else {
                JOptionPane.showMessageDialog(null, "Lưu xuống thất bại. Vui lòng kiểm tra lại!", "Lỗi", JOptionPane.YES_OPTION);
            }
        }
    }

    /**
     * Phương thức thuc hien cap nhat nhaaann viên xuống database
     *
     * @return
     */
    private void updateToDatabase() {
        
        if (checkData()) {
            String id = this.jxTxtStaffID.getText().trim();;//Ma nhan vien
            String name = Standard.standardNamePerson(this.jxTxtNameOfStaff.getText());//ten nhan vien
            String gender = this.jxCbGender.getSelectedItem().toString();//gioi tinh
            //Chuc vu
            PositionDTO objPosition = (PositionDTO) this.jxCbPosition.getSelectedItem();
            String idPosition= objPosition.getPositionID();//Ma chuc vu
            String phone = jxTxtPhone.getText().trim();
            String address = Standard.standardNamePerson(jxTxtAddress.getText().trim());
            java.sql.Date d = new java.sql.Date(jxDpBirthday.getDate().getYear(), 
                    jxDpBirthday.getDate().getMonth(),jxDpBirthday.getDate().getDate());//Ngay sinh
            String userName = jxTxtUserName.getText().trim();
            
            StaffDTO staffObj = new StaffDTO(id, name, gender, 
                    d, phone, address, idPosition, userName, "123456");
            if (m_StaffBLL.updateStaffToDatabase(staffObj)) {
                 JOptionPane.showOptionDialog(null,
                        "Câp nhật thành công!",
                        "Thông báo",
                        JOptionPane.YES_OPTION,
                        JOptionPane.QUESTION_MESSAGE,
                        null,
                        null,
                        null);
                //neu Cập nhật thanh cong
                this.jxtabDetails.m_isUpdate = false;
                initControls();
                refreshDataInJTable();
            } else {
                JOptionPane.showMessageDialog(null, "Cập nhật thất bại. Vui lòng kiểm tra lại!", "Lỗi", JOptionPane.YES_OPTION);
            }
        }
    }

    /**
     * Phương thức thiết lập các controls khi hủy thao tác thêm mới hay sửa đổi
     */
    private void cancelAction() {
        if (this.jxtabDetails.m_isAdd) {
            ((DefaultTableModel) jxtabDetails.getModel()).removeRow(jxtabDetails.getRowCount() - 1);
            this.jxtabDetails.m_isAdd = false;
            initControls();
            jxtabDetails.changeSelection(jxtabDetails.getRowCount() - 1, jxtabDetails.getRowCount() - 1, false, false);

        } else {
            this.jxtabDetails.m_isUpdate = false;
            initControls();
        }
        refreshDataInJTable();
    }

    /**
     * Phương thức kiểm tra dữ liệu có bi bỏ trống hay ko?
     * @return true: ko trống, false: trống
     */
    private boolean checkData()
    {
        if(jxTxtStaffID.getText().equals("")||
                jxTxtNameOfStaff.getText().equals("")||
                jxTxtAddress.getText().equals("")||
                jxTxtPhone.getText().equals("")||
                jxTxtUserName.getText().equals("")||
                jxCbGender.getSelectedIndex()== -1||
                jxCbPosition.getSelectedIndex()== -1||
                jxDpBirthday.getDate().equals(null)){
            
            JOptionPane.showOptionDialog(null,
                    "Dữ liệu không được bỏ trống. Vui lòng nhập lại!", 
                    "Cảnh báo",
                    JOptionPane.YES_OPTION,
                    JOptionPane.WARNING_MESSAGE,
                    null,
                    null,
                    null);
            return false;
        }
        else
        {
            if(Standard.compareDate(jxDpBirthday.getDate(), Standard.getDateSystem()) == 1||
                    Standard.compareDate(jxDpBirthday.getDate(), Standard.getDateSystem()) == 0){//ngay sinh phai nho hon hoac bang ngay hien tai
                int age = Standard.calculateAge(jxDpBirthday.getDate());
                if (age >= minAge && age <= maxAge) {
                    return true;
                } else {
                     JOptionPane.showMessageDialog(null, "Tuổi nhân viên không hợp lệ!");
                    return false;
                }
            }
            else
            {
                 JOptionPane.showMessageDialog(null, "Ngày sinh phải nhỏ hơn hoặc bằng ngày hiện tại!");
                    return false;
            }
        }
      
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jxpanDetails = new org.jdesktop.swingx.JXPanel();
        jpanTableDetails = new javax.swing.JPanel();
        jpanContent = new javax.swing.JPanel();
        jxpanFindNavibar = new org.jdesktop.swingx.JXPanel();
        jpanChose = new javax.swing.JPanel();
        jChkSearchWithMajorID = new javax.swing.JCheckBox();
        jChkSearchWithMajorName = new javax.swing.JCheckBox();
        jChkSearchFast = new javax.swing.JCheckBox();
        jChkSearchWithFacultyName = new javax.swing.JCheckBox();
        jChkSearchWithFacultyName1 = new javax.swing.JCheckBox();
        jxbtnFindVisible = new org.jdesktop.swingx.JXButton();
        jxSearchFaculty = new org.jdesktop.swingx.JXSearchField();
        jXLabel1 = new org.jdesktop.swingx.JXLabel();
        jScrollPane = new javax.swing.JScrollPane();
        jxtabDetails = new mnstudent.global.MyTable();
        jpanFuntionalDetails = new javax.swing.JPanel();
        jxBtnAdd = new org.jdesktop.swingx.JXButton();
        jxBtnUpdate = new org.jdesktop.swingx.JXButton();
        jxBtnDelete = new org.jdesktop.swingx.JXButton();
        jxBtnSave = new org.jdesktop.swingx.JXButton();
        jxBtnCancel = new org.jdesktop.swingx.JXButton();
        jxpanHeader = new org.jdesktop.swingx.JXPanel();
        jxpanTitleHeader = new org.jdesktop.swingx.JXPanel();
        jXLabel5 = new org.jdesktop.swingx.JXLabel();
        jxpanInfoHeader = new org.jdesktop.swingx.JXPanel();
        jxpanInfo = new org.jdesktop.swingx.JXPanel();
        jxLabFacultyID = new org.jdesktop.swingx.JXLabel();
        jxTxtStaffID = new org.jdesktop.swingx.JXTextField();
        jxLabNameOfFaculty = new org.jdesktop.swingx.JXLabel();
        jxTxtNameOfStaff = new org.jdesktop.swingx.JXTextField();
        jxLabNameOfFaculty1 = new org.jdesktop.swingx.JXLabel();
        jxCbPosition = new org.jdesktop.swingx.JXComboBox();
        jxLabFacultyID1 = new org.jdesktop.swingx.JXLabel();
        jxCbGender = new org.jdesktop.swingx.JXComboBox();
        jxLabNameOfFaculty2 = new org.jdesktop.swingx.JXLabel();
        jxDpBirthday = new org.jdesktop.swingx.JXDatePicker();
        jxTxtAddress = new org.jdesktop.swingx.JXTextField();
        jxLabNameOfFaculty4 = new org.jdesktop.swingx.JXLabel();
        jxLabNameOfFaculty5 = new org.jdesktop.swingx.JXLabel();
        jxTxtUserName = new org.jdesktop.swingx.JXTextField();
        jxLabNameOfFaculty6 = new org.jdesktop.swingx.JXLabel();
        jxTxtPhone = new org.jdesktop.swingx.JXTextField();

        setLayout(new java.awt.BorderLayout());

        jxpanDetails.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jxpanDetails.setLayout(new java.awt.BorderLayout());

        jpanTableDetails.setLayout(new java.awt.BorderLayout());

        jpanContent.setLayout(new java.awt.BorderLayout());

        jxpanFindNavibar.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jxpanFindNavibar.setPreferredSize(new java.awt.Dimension(914, 30));

        jpanChose.setBorder(javax.swing.BorderFactory.createTitledBorder("Chọn nội dung tìm kiếm"));

        jChkSearchWithMajorID.setText("Tìm theo mã nhân viên");

        jChkSearchWithMajorName.setText("Tìm theo tên nhân viên");

        jChkSearchFast.setText("Tìm kiếm nhanh");

        jChkSearchWithFacultyName.setText("Tìm theo chức vụ");

        jChkSearchWithFacultyName1.setText("Tìm theo điện thoại");

        javax.swing.GroupLayout jpanChoseLayout = new javax.swing.GroupLayout(jpanChose);
        jpanChose.setLayout(jpanChoseLayout);
        jpanChoseLayout.setHorizontalGroup(
            jpanChoseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanChoseLayout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addComponent(jChkSearchWithMajorID)
                .addGap(30, 30, 30)
                .addComponent(jChkSearchWithMajorName)
                .addGap(30, 30, 30)
                .addComponent(jChkSearchWithFacultyName)
                .addGap(30, 30, 30)
                .addComponent(jChkSearchWithFacultyName1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 141, Short.MAX_VALUE)
                .addComponent(jChkSearchFast)
                .addGap(108, 108, 108))
        );
        jpanChoseLayout.setVerticalGroup(
            jpanChoseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanChoseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jChkSearchWithMajorID)
                .addComponent(jChkSearchFast)
                .addComponent(jChkSearchWithFacultyName)
                .addComponent(jChkSearchWithMajorName)
                .addComponent(jChkSearchWithFacultyName1))
        );

        jxbtnFindVisible.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jxbtnFindVisible.setText("Tùy chọn");
        jxbtnFindVisible.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxbtnFindVisibleActionPerformed(evt);
            }
        });

        jXLabel1.setText("Tìm kiếm:");

        javax.swing.GroupLayout jxpanFindNavibarLayout = new javax.swing.GroupLayout(jxpanFindNavibar);
        jxpanFindNavibar.setLayout(jxpanFindNavibarLayout);
        jxpanFindNavibarLayout.setHorizontalGroup(
            jxpanFindNavibarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jxpanFindNavibarLayout.createSequentialGroup()
                .addComponent(jxbtnFindVisible, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jXLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jxSearchFaculty, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addComponent(jpanChose, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jxpanFindNavibarLayout.setVerticalGroup(
            jxpanFindNavibarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jxpanFindNavibarLayout.createSequentialGroup()
                .addGroup(jxpanFindNavibarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jxbtnFindVisible, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxSearchFaculty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpanChose, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jpanContent.add(jxpanFindNavibar, java.awt.BorderLayout.NORTH);

        jxtabDetails.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Mã nhân viên", "Tên nhân viên", "Giới tính", "Ngày sinh", "Điện thoại", "Địa chỉ", "Chức vụ", "Tên đăng nhập"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, true, true, true, true, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane.setViewportView(jxtabDetails);

        jpanContent.add(jScrollPane, java.awt.BorderLayout.CENTER);

        jpanTableDetails.add(jpanContent, java.awt.BorderLayout.CENTER);

        jpanFuntionalDetails.setLayout(new java.awt.GridBagLayout());

        jxBtnAdd.setText("Thêm mới");
        jxBtnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnAddActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 20;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(8, 10, 6, 9);
        jpanFuntionalDetails.add(jxBtnAdd, gridBagConstraints);

        jxBtnUpdate.setText("Sửa đổi");
        jxBtnUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnUpdateActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 20;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
        gridBagConstraints.insets = new java.awt.Insets(8, 10, 6, 8);
        jpanFuntionalDetails.add(jxBtnUpdate, gridBagConstraints);

        jxBtnDelete.setText("Xóa bỏ");
        jxBtnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnDeleteActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 20;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 4, 8);
        jpanFuntionalDetails.add(jxBtnDelete, gridBagConstraints);

        jxBtnSave.setText("Lưu xuống");
        jxBtnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnSaveActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 20;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(11, 9, 7, 8);
        jpanFuntionalDetails.add(jxBtnSave, gridBagConstraints);

        jxBtnCancel.setText("Hủy bỏ");
        jxBtnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnCancelActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 20;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(12, 9, 8, 9);
        jpanFuntionalDetails.add(jxBtnCancel, gridBagConstraints);

        jpanTableDetails.add(jpanFuntionalDetails, java.awt.BorderLayout.EAST);

        jxpanDetails.add(jpanTableDetails, java.awt.BorderLayout.CENTER);

        add(jxpanDetails, java.awt.BorderLayout.CENTER);

        jxpanHeader.setLayout(new java.awt.BorderLayout());

        jxpanTitleHeader.setBorder(new org.jdesktop.swingx.border.DropShadowBorder());

        jXLabel5.setForeground(new java.awt.Color(0, 102, 255));
        jXLabel5.setText("NHÂN VIÊN");
        jXLabel5.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        jxpanTitleHeader.add(jXLabel5);

        jxpanHeader.add(jxpanTitleHeader, java.awt.BorderLayout.PAGE_START);

        jxpanInfoHeader.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jxpanInfoHeader.setLayout(new java.awt.BorderLayout());

        jxpanInfo.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "THÔNG TIN", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP));

        jxLabFacultyID.setText("Mã nhân viên");

        jxTxtStaffID.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jxTxtStaffIDCaretUpdate(evt);
            }
        });

        jxLabNameOfFaculty.setText("Tên nhân viên");

        jxTxtNameOfStaff.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jxTxtNameOfStaffCaretUpdate(evt);
            }
        });
        jxTxtNameOfStaff.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jxTxtNameOfStaffKeyPressed(evt);
            }
        });

        jxLabNameOfFaculty1.setText("Chức vụ");

        jxCbPosition.setVerifyInputWhenFocusTarget(false);
        jxCbPosition.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jxCbPositionItemStateChanged(evt);
            }
        });

        jxLabFacultyID1.setText("Giới tính");

        jxCbGender.setVerifyInputWhenFocusTarget(false);
        jxCbGender.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jxCbGenderItemStateChanged(evt);
            }
        });

        jxLabNameOfFaculty2.setText("Ngày sinh");

        jxDpBirthday.setFormats("dd/MM/yyyy");
        jxDpBirthday.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxDpBirthdayActionPerformed(evt);
            }
        });

        jxTxtAddress.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jxTxtAddressCaretUpdate(evt);
            }
        });

        jxLabNameOfFaculty4.setText("Địa chỉ");

        jxLabNameOfFaculty5.setText("Điện thoại");

        jxTxtUserName.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jxTxtUserNameCaretUpdate(evt);
            }
        });

        jxLabNameOfFaculty6.setText("Tên đăng nhập");

        jxTxtPhone.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jxTxtPhoneKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jxpanInfoLayout = new javax.swing.GroupLayout(jxpanInfo);
        jxpanInfo.setLayout(jxpanInfoLayout);
        jxpanInfoLayout.setHorizontalGroup(
            jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jxpanInfoLayout.createSequentialGroup()
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jxpanInfoLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jxLabFacultyID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxLabFacultyID1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jxpanInfoLayout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(jxLabNameOfFaculty5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jxTxtStaffID, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
                    .addComponent(jxCbGender, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jxTxtPhone, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(62, 62, 62)
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jxLabNameOfFaculty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxLabNameOfFaculty2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxLabNameOfFaculty4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jxDpBirthday, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxTxtNameOfStaff, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
                    .addComponent(jxTxtAddress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(62, 62, 62)
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jxpanInfoLayout.createSequentialGroup()
                        .addComponent(jxLabNameOfFaculty6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jxTxtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jxpanInfoLayout.createSequentialGroup()
                        .addComponent(jxLabNameOfFaculty1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(51, 51, 51)
                        .addComponent(jxCbPosition, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jxpanInfoLayout.setVerticalGroup(
            jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jxpanInfoLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jxpanInfoLayout.createSequentialGroup()
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jxLabNameOfFaculty1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxCbPosition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jxTxtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxLabNameOfFaculty6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jxpanInfoLayout.createSequentialGroup()
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jxLabFacultyID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxTxtStaffID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxLabNameOfFaculty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxTxtNameOfStaff, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jxLabFacultyID1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxCbGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxLabNameOfFaculty2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxDpBirthday, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jxLabNameOfFaculty5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jxTxtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jxLabNameOfFaculty4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jxTxtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(4, 4, 4))
        );

        jxpanInfoHeader.add(jxpanInfo, java.awt.BorderLayout.CENTER);

        jxpanHeader.add(jxpanInfoHeader, java.awt.BorderLayout.CENTER);

        add(jxpanHeader, java.awt.BorderLayout.NORTH);
    }// </editor-fold>//GEN-END:initComponents

    private void jxbtnFindVisibleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxbtnFindVisibleActionPerformed
        if (jxbtnFindVisible.getText().equals("Đóng")) {
            jxbtnFindVisible.setPreferredSize(new Dimension(110, 25));
            jxbtnFindVisible.setText("Tùy chọn");
            jxbtnFindVisible.revalidate();
            jxpanFindNavibar.setPreferredSize(new Dimension(30, 30));
            jxpanFindNavibar.revalidate();
        } else {
            jxbtnFindVisible.setPreferredSize(new Dimension(20, 25));
            jxbtnFindVisible.setText("Đóng");
            jxbtnFindVisible.revalidate();
            jxpanFindNavibar.setPreferredSize(new Dimension(30, 105));
            jxpanFindNavibar.revalidate();
        }
    }//GEN-LAST:event_jxbtnFindVisibleActionPerformed

    private void jxBtnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnAddActionPerformed
        for (int i = 0; i < jxtabDetails.getColumnCount(); i++) {
            if (jxtabDetails.getValueAt(jxtabDetails.getRowCount() - 1, i).equals("")) {
                return;
            }
        }

        Vector newRow = new Vector(jxtabDetails.getColumnCount());
        for (int i = 0; i < jxtabDetails.getColumnCount(); i++) {
            newRow.addElement("");
        }
        ((DefaultTableModel) jxtabDetails.getModel()).addRow(newRow);
        jxtabDetails.setRowSelectionInterval(jxtabDetails.getRowCount() - 1, jxtabDetails.getRowCount() - 1);
        //jxtabDetails.setEnabled(false);
        //jxtabDetails.setRowSelectionAllowed(false);
        JScrollBar sb = jScrollPane.getVerticalScrollBar();
        sb.setValue(sb.getMaximum());

        if (!this.jxtabDetails.m_isAdd) {
            this.jxtabDetails.m_isAdd = true;
            initControls();
            this.jxtabDetails.m_rowIndex = jxtabDetails.getRowCount() - 1;
            resetControls();
        }
    }//GEN-LAST:event_jxBtnAddActionPerformed

    private void jxTxtStaffIDCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jxTxtStaffIDCaretUpdate
        if (this.jxtabDetails.m_isAdd)
            jxtabDetails.getModel().setValueAt(jxTxtStaffID.getText(), jxtabDetails.getRowCount() - 1, 0);
        else 
            if (this.jxtabDetails.m_isUpdate)
                jxtabDetails.getModel().setValueAt(jxTxtStaffID.getText(), jxtabDetails.getSelectedRow(), 0);

    }//GEN-LAST:event_jxTxtStaffIDCaretUpdate

    private void jxTxtNameOfStaffCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jxTxtNameOfStaffCaretUpdate

        if(this.jxtabDetails.m_isAdd){
            jxtabDetails.getModel().setValueAt(jxTxtNameOfStaff.getText(), jxtabDetails.getRowCount()-1, 1);
            jxTxtUserName.setText(Standard.createUserName(jxTxtNameOfStaff.getText(), (Standard.getDateSystem().getYear()+1900)));
        }
        else
            if(this.jxtabDetails.m_isUpdate){
                jxtabDetails.getModel().setValueAt(jxTxtNameOfStaff.getText(), jxtabDetails.getSelectedRow(), 1);
                jxTxtUserName.setText(Standard.createUserName(jxTxtNameOfStaff.getText(), (Standard.getDateSystem().getYear()+1900)));
            }
    }//GEN-LAST:event_jxTxtNameOfStaffCaretUpdate

    private void jxBtnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnDeleteActionPerformed
        int rs = JOptionPane.showOptionDialog(null,
                "Bạn có muốn xóa không!",
                "Câu hỏi",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE,
                null,
                null,
                null);
        if (rs == 0) {
            if (isDeleteMoreStaff()) {
                JOptionPane.showOptionDialog(null,
                        "Xóa thành công!",
                        "Thông báo",
                        JOptionPane.YES_OPTION,
                        JOptionPane.INFORMATION_MESSAGE,
                        null,
                        null,
                        null);
                //neu luu thanh cong
                this.jxtabDetails.m_isAdd = false;
                initControls();
                refreshDataInJTable();
            } else {
                JOptionPane.showMessageDialog(null, "Xóa thất bại. Vui lòng kiểm tra lại!", "Lỗi", JOptionPane.YES_OPTION);
            }
        }
    }//GEN-LAST:event_jxBtnDeleteActionPerformed

    private void jxBtnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnSaveActionPerformed
        save();
    }//GEN-LAST:event_jxBtnSaveActionPerformed

    private void jxBtnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnCancelActionPerformed

        cancelAction();
    }//GEN-LAST:event_jxBtnCancelActionPerformed

    private void jxCbPositionItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jxCbPositionItemStateChanged
        if(jxCbPosition.getSelectedItem() != null){
            PositionDTO obj = (PositionDTO) evt.getItem();
            if (obj.equals(objAddNew)) {
                JOptionPane.showMessageDialog(null, "Thêm mới Chuc vu!");
                jxCbPosition.setSelectedItem(null);
            } else {
                if (this.jxtabDetails.m_isAdd || this.jxtabDetails.m_isUpdate) {
                    jxtabDetails.getModel().setValueAt(obj, currentRow, 6);
                }
            }
        }
    }//GEN-LAST:event_jxCbPositionItemStateChanged

    private void jxBtnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnUpdateActionPerformed

        this.jxtabDetails.m_isUpdate = true;
        initControls();
        jxTxtNameOfStaff.requestFocus();
    }//GEN-LAST:event_jxBtnUpdateActionPerformed

    private void jxTxtNameOfStaffKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jxTxtNameOfStaffKeyPressed

      if(jxTxtNameOfStaff.getText().length()>Standard.MAX_LEN)
            jxTxtNameOfStaff.setText(jxTxtNameOfStaff.getText().substring(0, Standard.MAX_LEN));
    }//GEN-LAST:event_jxTxtNameOfStaffKeyPressed

    private void jxCbGenderItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jxCbGenderItemStateChanged

        if(jxCbGender.getSelectedItem() != null)
        {
            if(jxtabDetails.m_isAdd||jxtabDetails.m_isUpdate)
            {
                String gender = jxCbGender.getSelectedItem().toString();
                jxtabDetails.getModel().setValueAt(gender, jxtabDetails.getSelectedRow(), 2);
            }
        }
        
    }//GEN-LAST:event_jxCbGenderItemStateChanged

    private void jxTxtAddressCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jxTxtAddressCaretUpdate

        if (this.jxtabDetails.m_isAdd)
            jxtabDetails.getModel().setValueAt(jxTxtAddress.getText(), jxtabDetails.getRowCount() - 1, 5);
        else 
            if (this.jxtabDetails.m_isUpdate)
                jxtabDetails.getModel().setValueAt(jxTxtAddress.getText(), jxtabDetails.getSelectedRow(), 5);
    }//GEN-LAST:event_jxTxtAddressCaretUpdate

    private void jxTxtUserNameCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jxTxtUserNameCaretUpdate
        if (this.jxtabDetails.m_isAdd)
            jxtabDetails.getModel().setValueAt(jxTxtStaffID.getText(), jxtabDetails.getRowCount() - 1, 7);
        else 
            if (this.jxtabDetails.m_isUpdate)
                jxtabDetails.getModel().setValueAt(jxTxtStaffID.getText(), jxtabDetails.getSelectedRow(), 7);
    }//GEN-LAST:event_jxTxtUserNameCaretUpdate

    private void jxDpBirthdayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxDpBirthdayActionPerformed
        if(jxtabDetails.m_isAdd||jxtabDetails.m_isUpdate)
        {
            String date = formatDate.format(jxDpBirthday.getDate());
            jxtabDetails.getModel().setValueAt(date, jxtabDetails.getSelectedRow(), 3);
        }
           
    }//GEN-LAST:event_jxDpBirthdayActionPerformed

    private void jxTxtPhoneKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jxTxtPhoneKeyPressed
       
    }//GEN-LAST:event_jxTxtPhoneKeyPressed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox jChkSearchFast;
    private javax.swing.JCheckBox jChkSearchWithFacultyName;
    private javax.swing.JCheckBox jChkSearchWithFacultyName1;
    private javax.swing.JCheckBox jChkSearchWithMajorID;
    private javax.swing.JCheckBox jChkSearchWithMajorName;
    private javax.swing.JScrollPane jScrollPane;
    private org.jdesktop.swingx.JXLabel jXLabel1;
    private org.jdesktop.swingx.JXLabel jXLabel5;
    private javax.swing.JPanel jpanChose;
    private javax.swing.JPanel jpanContent;
    private javax.swing.JPanel jpanFuntionalDetails;
    private javax.swing.JPanel jpanTableDetails;
    private org.jdesktop.swingx.JXButton jxBtnAdd;
    private org.jdesktop.swingx.JXButton jxBtnCancel;
    private org.jdesktop.swingx.JXButton jxBtnDelete;
    private org.jdesktop.swingx.JXButton jxBtnSave;
    private org.jdesktop.swingx.JXButton jxBtnUpdate;
    private org.jdesktop.swingx.JXComboBox jxCbGender;
    private org.jdesktop.swingx.JXComboBox jxCbPosition;
    private org.jdesktop.swingx.JXDatePicker jxDpBirthday;
    private org.jdesktop.swingx.JXLabel jxLabFacultyID;
    private org.jdesktop.swingx.JXLabel jxLabFacultyID1;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty1;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty2;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty4;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty5;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty6;
    private org.jdesktop.swingx.JXSearchField jxSearchFaculty;
    private org.jdesktop.swingx.JXTextField jxTxtAddress;
    private org.jdesktop.swingx.JXTextField jxTxtNameOfStaff;
    private org.jdesktop.swingx.JXTextField jxTxtPhone;
    private org.jdesktop.swingx.JXTextField jxTxtStaffID;
    private org.jdesktop.swingx.JXTextField jxTxtUserName;
    private org.jdesktop.swingx.JXButton jxbtnFindVisible;
    private org.jdesktop.swingx.JXPanel jxpanDetails;
    private org.jdesktop.swingx.JXPanel jxpanFindNavibar;
    private org.jdesktop.swingx.JXPanel jxpanHeader;
    private org.jdesktop.swingx.JXPanel jxpanInfo;
    private org.jdesktop.swingx.JXPanel jxpanInfoHeader;
    private org.jdesktop.swingx.JXPanel jxpanTitleHeader;
    private mnstudent.global.MyTable jxtabDetails;
    // End of variables declaration//GEN-END:variables
}
